package cn.ym.common.utils;

import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ProjectName: SprintgbootCuteCat
 * @Package: cn.ym.common.utils
 * @ClassName: OkHttpUtil
 * @Author: yiming
 * @Description: okhttp工具
 * @Date: 2022/2/16 13:31
 * @Version: 1.0
 */
public class OkHttpUtil {
    private static final Logger LOG = LoggerFactory.getLogger(OkHttpUtil.class);

    public static void sendMessage(String wxid_to,String msg) throws IOException
    {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{    \"event\": \"SendTextMsg\",    \"robot_wxid\": \""+wxid_to+"\",   \"to_wxid\":\""+wxid_to+"\",   \"msg\": \""+msg+"\"}");
        Request request = new Request.Builder()
                .url("http://127.0.0.1:8090/")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        LOG.info(response.toString());
    }
}
